package com.ww.springboot.boot.baseTest.date;

import cn.hutool.core.date.DateUtil;

import java.time.*;
import java.util.Date;
import java.util.TimeZone;

/**
 * 描述：
 *
 * @author 🧑 ‍wanwei
 * @since 2025-01-20 14:43
 */
public class TimeConvertDemo {

    public static void main(String[] args) {
        LocalDateTime localDateTime = LocalDateTime.of(2025, 1, 1, 1, 1, 1);

        //替换day
        System.out.println(localDateTime.withDayOfYear(340));
        System.out.println(localDateTime.withHour(2));
        System.out.println(localDateTime.withNano(2));
        System.out.println(localDateTime.withDayOfMonth(25));
        System.out.println(localDateTime.withYear(2024));

        System.out.println(localDateTime.getDayOfYear());
        System.out.println(localDateTime.getDayOfMonth());
        System.out.println(localDateTime.getDayOfWeek());
        System.out.println(localDateTime.getYear());
        System.out.println(localDateTime.getMonthValue());
        System.out.println(localDateTime.getDayOfYear());
        System.out.println(localDateTime.getHour());
        System.out.println(localDateTime.getMinute());
        System.out.println(localDateTime.getSecond());
        System.out.println(localDateTime.getNano());
        System.out.println(localDateTime.minusDays(1));
        System.out.println(localDateTime.minusDays(2));
        System.out.println(localDateTime.minusDays(-2));
        System.out.println(localDateTime.minusMonths(1));
        System.out.println(localDateTime.minusMonths(2));
        System.out.println(localDateTime.minusMonths(3));
        System.out.println(localDateTime);

        Instant instant = localDateTime.toInstant(ZoneOffset.UTC);
        Date from = Date.from(instant);
        System.out.println(DateUtil.format(from, "yyyy-MM-dd HH:mm:ss"));


        ZonedDateTime zonedDateTime = localDateTime.atZone(ZoneId.of("America/New_York"));
        Date from2 = Date.from(zonedDateTime.toInstant());
        System.out.println(DateUtil.format(from2, "yyyy-MM-dd HH:mm:ss"));

        //带时区的时间
        zonedDateTime = localDateTime.atZone(ZoneId.systemDefault());
        from2 = Date.from(zonedDateTime.toInstant());
        System.out.println(DateUtil.format(from2, "yyyy-MM-dd HH:mm:ss"));

        zonedDateTime = localDateTime.atZone(ZoneId.of("Asia/Shanghai"));
        from2 = Date.from(zonedDateTime.toInstant());
        System.out.println(DateUtil.format(from2, "yyyy-MM-dd HH:mm:ss"));

        System.out.println(TimeZone.getDefault().toZoneId());
    }
}
